import { createRouter, createWebHistory } from 'vue-router'

import NormalLayout from '@/layout/normal/NormalLayout'

import mainPage from '@/views/index/MainPage'
import login from '@/views/user/UserLogin'
import register from '@/views/user/UserRegister'

// 定义路由
const routes = [
  {
    path: '/',
    name: 'Home',
    component: mainPage // 首页
  },
  {
    path: '/login',
    name: 'Login',
    component: login // 登录页
  },
  {
    path: '/register',
    name: 'Register',
    component: register // 注册页
  },
  {
    path: '/permission',
    name: 'Permission',
    component: NormalLayout, // 权限管理界面
    meta: {
      title: '权限管理',
      roles: [ 'admin' ]
    },
    redirect: '/permission/user',
    children: [
      {
        path: 'role',
        component: () => import('@/views/permission/RoleManage'),
        name: 'RoleManage',
        meta: {
          title: '角色管理',
          roles: [ 'admin' ]
        }
      },
      {
        path: 'user',
        component: () => import('@/views/permission/UserManage'),
        name: 'UserManage',
        meta: {
          title: '用户管理'
        }
      },
      {
        path: 'menu',
        component: () => import('@/views/permission/MenuManage'),
        name: 'MenuManage',
        meta: {
          title: '菜单管理'
        }
      }
    ]
  },
  {
    path: '/system',
    name: 'System',
    component: NormalLayout, // 系统管理界面
    redirect: '/system/dictionary',
    meta: {
      title: '系统管理',
      roles: [ 'admin' ]
    },
    children: [
      {
        path: 'dictionary',
        component: () => import('@/views/system/DictionaryManage'),
        name: 'DictionaryManage',
        meta: {
          title: '字典管理'
        }
      },
      {
        path: 'file',
        component: () => import('@/views/system/FileManage'),
        name: 'FileManage',
        meta: {
          title: '文件管理'
        }
      }
    ]
  }
]

// 创建路由实例
const router = createRouter({
  history: createWebHistory(), // 使用 HTML5 History 模式
  routes // `routes` 配置
})

export default router
